<HTML>
  <HEAD>
    <TITLE>threadpool Documentation</TITLE>
    <LINK HREF="threadpool.css" REL="stylesheet" TYPE="text/css">
  </HEAD>
  <BODY BGCOLOR="#FFFFFF">

    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>

          <TD ALIGN="LEFT">
            <B>threadpool</B>
          </TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="../index.html">Overview</A> |
            <A CLASS="qindex" HREF="../reference/annotated.html">Reference</A> |
            <A CLASS="qindex" HREF="../tutorial/intro.html">Tutorial</A> |
            <A CLASS="qindex" HREF="../examples/intro.html">Examples</A> |
            <A CLASS="qindex" HREF="../design/intro.html">Design</A>
          </TD>

        </TR>
      </TABLE>
    </DIV>
    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>
          <TD ALIGN="LEFT">
            <B>Reference</B>
          </TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="annotated.html">Class List</A> |
            <A CLASS="qindex" HREF="functions.html">Member Functions</A> |
            <A CLASS="qindex" HREF="namespacemembers.html">Typedefs</A> |
            <A CLASS="qindex" HREF="files.html">File List</A>
          </TD>
        </TR>
      </TABLE>
    </DIV>
<!-- Generated by Doxygen 1.4.6-NO -->
<h1>threadpool/pool.hpp</h1><a href="a00029.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 
<a name="l00022"></a>00022 <span class="preprocessor">#ifndef THREADPOOL_POOL_HPP_INCLUDED</span>
<a name="l00023"></a>00023 <span class="preprocessor"></span><span class="preprocessor">#define THREADPOOL_POOL_HPP_INCLUDED</span>
<a name="l00024"></a>00024 <span class="preprocessor"></span>
<a name="l00025"></a>00025 <span class="preprocessor">#include &lt;boost/ref.hpp&gt;</span>
<a name="l00026"></a>00026 
<a name="l00027"></a>00027 <span class="preprocessor">#include "detail/pool_core.hpp"</span>
<a name="l00028"></a>00028 
<a name="l00029"></a>00029 <span class="preprocessor">#include "<a class="code" href="a00034.html">task_adaptors.hpp</a>"</span>
<a name="l00030"></a>00030 
<a name="l00031"></a>00031 <span class="preprocessor">#include "detail/locking_ptr.hpp"</span>
<a name="l00032"></a>00032 
<a name="l00033"></a>00033 <span class="preprocessor">#include "<a class="code" href="a00031.html">scheduling_policies.hpp</a>"</span>
<a name="l00034"></a>00034 <span class="preprocessor">#include "<a class="code" href="a00033.html">size_policies.hpp</a>"</span>
<a name="l00035"></a>00035 <span class="preprocessor">#include "<a class="code" href="a00032.html">shutdown_policies.hpp</a>"</span>
<a name="l00036"></a>00036 
<a name="l00037"></a>00037 
<a name="l00038"></a>00038 
<a name="l00040"></a>00040 <span class="keyword">namespace </span>boost { <span class="keyword">namespace </span>threadpool
<a name="l00041"></a>00041 {
<a name="l00042"></a>00042 
<a name="l00043"></a>00043 
<a name="l00044"></a>00044 
<a name="l00066"></a>00066   <span class="keyword">template</span> &lt;
<a name="l00067"></a>00067     <span class="keyword">typename</span> Task                                   = <a class="code" href="a00036.html#c6f15485d0c9225572afc57b30f50358">task_func</a>,
<a name="l00068"></a>00068     <span class="keyword">template</span> &lt;<span class="keyword">typename</span>&gt; <span class="keyword">class </span>SchedulingPolicy      = fifo_scheduler,
<a name="l00069"></a>00069     <span class="keyword">template</span> &lt;<span class="keyword">typename</span>&gt; <span class="keyword">class </span>SizePolicy            = static_size,
<a name="l00070"></a>00070     <span class="keyword">template</span> &lt;<span class="keyword">typename</span>&gt; <span class="keyword">class </span>SizePolicyController  = resize_controller,
<a name="l00071"></a>00071     <span class="keyword">template</span> &lt;<span class="keyword">typename</span>&gt; <span class="keyword">class </span>ShutdownPolicy        = wait_for_all_tasks
<a name="l00072"></a>00072   &gt; 
<a name="l00073"></a><a class="code" href="a00024.html">00073</a>   <span class="keyword">class </span><a class="code" href="a00024.html">thread_pool</a> 
<a name="l00074"></a>00074   {
<a name="l00075"></a>00075     <span class="keyword">typedef</span> detail::pool_core&lt;Task, 
<a name="l00076"></a>00076                               SchedulingPolicy,
<a name="l00077"></a>00077                               SizePolicy,
<a name="l00078"></a>00078                               SizePolicyController,
<a name="l00079"></a>00079                               ShutdownPolicy&gt; pool_core_type;
<a name="l00080"></a>00080     shared_ptr&lt;pool_core_type&gt;          m_core; <span class="comment">// pimpl idiom</span>
<a name="l00081"></a>00081     shared_ptr&lt;void&gt;                    m_shutdown_controller; <span class="comment">// If the last pool holding a pointer to the core is deleted the controller shuts the pool down.</span>
<a name="l00082"></a>00082 
<a name="l00083"></a>00083   <span class="keyword">public</span>: <span class="comment">// Type definitions</span>
<a name="l00084"></a><a class="code" href="a00024.html#321da9e252f14645cd3e433305576a4b">00084</a>     <span class="keyword">typedef</span> Task <a class="code" href="a00024.html#321da9e252f14645cd3e433305576a4b">task_type</a>;                                   
<a name="l00085"></a><a class="code" href="a00024.html#4bdb3cef94393456f2b7ec0d171d6b11">00085</a>     <span class="keyword">typedef</span> SchedulingPolicy&lt;task_type&gt; <a class="code" href="a00024.html#4bdb3cef94393456f2b7ec0d171d6b11">scheduler_type</a>;       
<a name="l00086"></a>00086  <span class="comment">/*   typedef thread_pool&lt;Task, </span>
<a name="l00087"></a>00087 <span class="comment">                        SchedulingPolicy,</span>
<a name="l00088"></a>00088 <span class="comment">                        SizePolicy,</span>
<a name="l00089"></a>00089 <span class="comment">                        ShutdownPolicy &gt; pool_type;          //!&lt; Indicates the thread pool's type.</span>
<a name="l00090"></a>00090 <span class="comment"> */</span>
<a name="l00091"></a><a class="code" href="a00024.html#654dc8a75dc2ea813dc6307f8707658d">00091</a>     <span class="keyword">typedef</span> SizePolicy&lt;pool_core_type&gt; <a class="code" href="a00024.html#654dc8a75dc2ea813dc6307f8707658d">size_policy_type</a>; 
<a name="l00092"></a><a class="code" href="a00024.html#c7e01650ffec650c0279782eacb4be80">00092</a>     <span class="keyword">typedef</span> SizePolicyController&lt;pool_core_type&gt; <a class="code" href="a00024.html#c7e01650ffec650c0279782eacb4be80">size_controller_type</a>;
<a name="l00093"></a>00093 
<a name="l00094"></a>00094 
<a name="l00095"></a>00095   <span class="keyword">public</span>:
<a name="l00099"></a><a class="code" href="a00024.html#6eba12acd49dfe14c7de44073a138aa1">00099</a>     <a class="code" href="a00024.html#6eba12acd49dfe14c7de44073a138aa1">thread_pool</a>(size_t initial_threads = 0)
<a name="l00100"></a>00100     : m_core(new pool_core_type)
<a name="l00101"></a>00101     , m_shutdown_controller(static_cast&lt;void*&gt;(0), bind(&amp;pool_core_type::shutdown, m_core))
<a name="l00102"></a>00102     {
<a name="l00103"></a>00103       size_policy_type::init(*m_core, initial_threads);
<a name="l00104"></a>00104     }
<a name="l00105"></a>00105 
<a name="l00106"></a>00106 
<a name="l00111"></a><a class="code" href="a00024.html#965f249200025312bd3a3a0f8144e3a5">00111</a>     <a class="code" href="a00024.html#c7e01650ffec650c0279782eacb4be80">size_controller_type</a> <a class="code" href="a00024.html#965f249200025312bd3a3a0f8144e3a5">size_controller</a>()
<a name="l00112"></a>00112     {
<a name="l00113"></a>00113       <span class="keywordflow">return</span> m_core-&gt;size_controller();
<a name="l00114"></a>00114     }
<a name="l00115"></a>00115 
<a name="l00116"></a>00116 
<a name="l00120"></a><a class="code" href="a00024.html#f0d21c4108b9808946ed8dabbbe2687f">00120</a>     size_t <a class="code" href="a00024.html#f0d21c4108b9808946ed8dabbbe2687f">size</a>()<span class="keyword"> const</span>
<a name="l00121"></a>00121 <span class="keyword">    </span>{
<a name="l00122"></a>00122       <span class="keywordflow">return</span> m_core-&gt;size();
<a name="l00123"></a>00123     }
<a name="l00124"></a>00124 
<a name="l00125"></a>00125 
<a name="l00130"></a><a class="code" href="a00024.html#3daf5e17f6c2ba9a0ecdeb73b41478e6">00130</a>      <span class="keywordtype">bool</span> <a class="code" href="a00024.html#3daf5e17f6c2ba9a0ecdeb73b41478e6">schedule</a>(<a class="code" href="a00024.html#321da9e252f14645cd3e433305576a4b">task_type</a> <span class="keyword">const</span> &amp; task)
<a name="l00131"></a>00131      {  
<a name="l00132"></a>00132        <span class="keywordflow">return</span> m_core-&gt;schedule(task);
<a name="l00133"></a>00133      }
<a name="l00134"></a>00134 
<a name="l00135"></a>00135 
<a name="l00139"></a><a class="code" href="a00024.html#ab990245fb601499bc768737f65b09b2">00139</a>     size_t <a class="code" href="a00024.html#ab990245fb601499bc768737f65b09b2">active</a>()<span class="keyword"> const</span>
<a name="l00140"></a>00140 <span class="keyword">    </span>{
<a name="l00141"></a>00141       <span class="keywordflow">return</span> m_core-&gt;active();
<a name="l00142"></a>00142     }
<a name="l00143"></a>00143 
<a name="l00144"></a>00144 
<a name="l00148"></a><a class="code" href="a00024.html#1cea841e4310d6ff8a09f3f81124f45b">00148</a>     size_t <a class="code" href="a00024.html#1cea841e4310d6ff8a09f3f81124f45b">pending</a>()<span class="keyword"> const</span>
<a name="l00149"></a>00149 <span class="keyword">    </span>{
<a name="l00150"></a>00150       <span class="keywordflow">return</span> m_core-&gt;pending();
<a name="l00151"></a>00151     }
<a name="l00152"></a>00152 
<a name="l00153"></a>00153 
<a name="l00156"></a><a class="code" href="a00024.html#9d98ecc57fb790ad12e9c12dcead921b">00156</a>     <span class="keywordtype">void</span> <a class="code" href="a00024.html#9d98ecc57fb790ad12e9c12dcead921b">clear</a>()
<a name="l00157"></a>00157     { 
<a name="l00158"></a>00158       m_core-&gt;clear();
<a name="l00159"></a>00159     }    
<a name="l00160"></a>00160 
<a name="l00161"></a>00161 
<a name="l00166"></a><a class="code" href="a00024.html#4d8cacdeef78219399343a0bea999212">00166</a>     <span class="keywordtype">bool</span> <a class="code" href="a00024.html#4d8cacdeef78219399343a0bea999212">empty</a>()<span class="keyword"> const</span>
<a name="l00167"></a>00167 <span class="keyword">    </span>{
<a name="l00168"></a>00168       <span class="keywordflow">return</span> m_core-&gt;empty();
<a name="l00169"></a>00169     } 
<a name="l00170"></a>00170 
<a name="l00171"></a>00171 
<a name="l00176"></a><a class="code" href="a00024.html#dc8ccb7588160208ea0fd1d84b58269e">00176</a>     <span class="keywordtype">void</span> <a class="code" href="a00024.html#dc8ccb7588160208ea0fd1d84b58269e">wait</a>(size_t task_threshold = 0)<span class="keyword"> const</span>
<a name="l00177"></a>00177 <span class="keyword">    </span>{
<a name="l00178"></a>00178       m_core-&gt;wait(task_threshold);
<a name="l00179"></a>00179     } 
<a name="l00180"></a>00180 
<a name="l00181"></a>00181 
<a name="l00189"></a><a class="code" href="a00024.html#f229154a61cb29bc3ce969974eca3175">00189</a>     <span class="keywordtype">bool</span> <a class="code" href="a00024.html#dc8ccb7588160208ea0fd1d84b58269e">wait</a>(xtime <span class="keyword">const</span> &amp; timestamp, size_t task_threshold = 0)<span class="keyword"> const</span>
<a name="l00190"></a>00190 <span class="keyword">    </span>{
<a name="l00191"></a>00191       <span class="keywordflow">return</span> m_core-&gt;wait(timestamp, task_threshold);
<a name="l00192"></a>00192     }
<a name="l00193"></a>00193   };
<a name="l00194"></a>00194 
<a name="l00195"></a>00195 
<a name="l00196"></a>00196 
<a name="l00202"></a><a class="code" href="a00036.html#7570aa50154a35bba415deb195f56ae6">00202</a>   <span class="keyword">typedef</span> <a class="code" href="a00024.html">thread_pool&lt;task_func, fifo_scheduler, static_size, resize_controller, wait_for_all_tasks&gt;</a> <a class="code" href="a00024.html">fifo_pool</a>;
<a name="l00203"></a>00203 
<a name="l00204"></a>00204 
<a name="l00210"></a><a class="code" href="a00036.html#80846aad706981b61bdad8cfe43f581c">00210</a>   <span class="keyword">typedef</span> <a class="code" href="a00024.html">thread_pool&lt;task_func, lifo_scheduler, static_size, resize_controller, wait_for_all_tasks&gt;</a> <a class="code" href="a00024.html">lifo_pool</a>;
<a name="l00211"></a>00211 
<a name="l00212"></a>00212 
<a name="l00218"></a><a class="code" href="a00036.html#2b7a71ddf4d7c9fd40b9f5141ac518e1">00218</a>   <span class="keyword">typedef</span> <a class="code" href="a00024.html">thread_pool&lt;prio_task_func, prio_scheduler, static_size, resize_controller, wait_for_all_tasks&gt;</a> <a class="code" href="a00024.html">prio_pool</a>;
<a name="l00219"></a>00219 
<a name="l00220"></a>00220 
<a name="l00226"></a><a class="code" href="a00036.html#1e167909d0dce03e625576f80359b8fb">00226</a>   <span class="keyword">typedef</span> <a class="code" href="a00024.html">fifo_pool</a> <a class="code" href="a00024.html">pool</a>;
<a name="l00227"></a>00227 
<a name="l00228"></a>00228 
<a name="l00229"></a>00229 
<a name="l00230"></a>00230 } } <span class="comment">// namespace boost::threadpool</span>
<a name="l00231"></a>00231 
<a name="l00232"></a>00232 <span class="preprocessor">#endif // THREADPOOL_POOL_HPP_INCLUDED</span>
</pre></div>    <BR>
    <DIV CLASS="qindex">
      <TABLE BORDER="0" WIDTH="100%">
        <TR>
		  <TD CLASS="tiny" ALIGN="LEFT">Copyright &copy 2005-2007 Philipp Henkel</TD>
          <TD ALIGN="RIGHT">
            <A CLASS="qindex" HREF="../index.html">Overview</A> |
            <A CLASS="qindex" HREF="../reference/annotated.html">Reference</A> |
            <A CLASS="qindex" HREF="../tutorial/intro.html">Tutorial</A> |
            <A CLASS="qindex" HREF="../examples/intro.html">Examples</A> |
            <A CLASS="qindex" HREF="../design/intro.html">Design</A>
          </TD>
        </TR>       
      </TABLE>
    </DIV>  
  </BODY>
</HTML>
